//
//  ScoreViewController.m
//  edu
//
//  Created by baobaodp on 13-8-23.
//  Copyright (c) 2013年 baobaodp. All rights reserved.
//

#import "ScoreViewController.h"
#import "ScoreCell.h"
#import "ScoreListViewController.h"
#import "EduViewController.h"
#import "DBbase.h"

@interface ScoreViewController ()

@end

@implementation ScoreViewController

@synthesize imgNames;

-(id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        // Custom initialization
        self.isWithSearchBar = TRUE;
    }
    return self;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.imgNames = [NSArray arrayWithObjects:@"blue circle", @"green circle", @"orange circle", @"yellow circle", nil];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -
#pragma mark Table Data Source Methods
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 85;
}
- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section
{
    [self getRecords];
    return [self.datas count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"ScoreCellIdentifier";
    
    ScoreCell *cell = (ScoreCell *)[tableView
                                                  dequeueReusableCellWithIdentifier: cellIdentifier];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ScoreCell"
                                                     owner:self options:nil];
        for (id oneObject in nib)
            if ([oneObject isKindOfClass:[ScoreCell class]])
                cell = (ScoreCell *)oneObject;
    }
	
    NSUInteger row = [indexPath row];
    
    //图片index计算
    NSUInteger index = row % 4;
    
    [cell setData:[self.datas objectAtIndex:row] index:row imgName:[self.imgNames objectAtIndex:index]];
    
    [self configureCell:cell indexPath:indexPath accessoryType:DISCLOSURE_INDICATOR];
    
    //------cell背景透明化--------------------------------------------
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor clearColor];
    cell.contentView.backgroundColor = [UIColor clearColor];
    UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
    backView.backgroundColor = [UIColor clearColor];
    cell.backgroundView = backView;
    //--------------------------------------------------
    
    return cell;
}

#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    // Navigation logic may go here. Create and push another view controller.
	
	ScoreListViewController *detailViewController = [[ScoreListViewController alloc] initWithNibName:@"ScoreListViewController" bundle:nil];
    detailViewController.isSelfInfo = true;
    
    NSUInteger row = [indexPath row];
    detailViewController.condition =[self.datas objectAtIndex:row];
    
	// Pass the selected object to the new view controller.
	
	if (tableView == self.searchDisplayController.searchResultsTableView){
        //		detailViewController.currentLineName = [filteredListContent objectAtIndex:indexPath.row];
        //		detailViewController.currentLineIndex = [[CDataContainer Instance].lineNameArray indexOfObject:[filteredListContent objectAtIndex:indexPath.row]];
	}
	else{
        //		detailViewController.currentLineName = [[CDataContainer Instance].lineNameArray objectAtIndex:indexPath.row];
        //		detailViewController.currentLineIndex = indexPath.row;
	}
    
	[self.navigationController pushViewController:detailViewController animated:YES];
    
    
}

-(void)getRecords
{
    NSString *schId = [userEntry.userInfo getFieldValueByName:@"sch_Id"];
    NSString *querySql = [NSString stringWithFormat:@"select * from T_TestPtn where sch_Id ='%@' order by TP_date desc" ,schId];
    
    const char *sql = [querySql UTF8String];
    
    self.datas = getDbRecords(sql,@"T_TestPtn",[NSArray arrayWithObjects:@"ptn_Id", nil]);
}
@end
